package com.example.mybatisplus.pojo;

import com.baomidou.mybatisplus.annotation.*;
import com.example.mybatisplus.typehandler.TestTypeHandler;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.List;

@AllArgsConstructor
@NoArgsConstructor
@Data
@TableName(value = "one")
@Accessors(chain = true)
public class One {

    //默认是ASSIGN_ID，注意：主键自动生成，需要该字段为Long类型
    @TableField(fill = FieldFill.INSERT)
    @TableId(value = "one_id",type = IdType.ASSIGN_ID)
    private Long id;
    private String oneName;
    private Integer oneAge;
    @TableField(fill=FieldFill.INSERT_UPDATE)
    //@DateTimeFormat需要添加依赖，可以参考笔记
    private Date oneCreateTime;
    @TableField(value = "other_id")
    private Other other;
    @TableField(exist = false,insertStrategy = FieldStrategy.NEVER,updateStrategy = FieldStrategy.NEVER)
    private List<More> moreList;

    public One(String name,Integer oneAge,Date oneCreateTime,Other other){
        this.oneName=name;
        this.oneAge=oneAge;
        this.oneCreateTime=oneCreateTime;
        this.other=other;
    }

    @Override
    public String toString() {
        String str="One{" +
                "id=" + id +
                ", oneName='" + oneName + '\'' +
                ", oneAge=" + oneAge +
                ", oneCreateTime=" + oneCreateTime;
        if(other!=null){
            str+= ", other={"+
                    "id:"+ other.getId() +
                    "otherName:"+other.getOtherName()+
                    "otherCreateTime:"+other.getOtherCreateTime()+
                    '}';
        }
        if(moreList!=null){
            str+=",moreList="+moreList.toString();
        }
        return str;
    }
}
